import Vue from 'vue';
import Vuex from 'vuex';
import getters from './getters';
// import
Vue.use(Vuex);

const modulesFiles = require.context('./modules', false, /\.js$/);

const modules = modulesFiles.keys().reduce((mm, modulePath) => {
  const m = mm;
  // set './app.js' => 'app'
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1');
  const value = modulesFiles(modulePath);
  m[moduleName] = value.default;
  return m;
}, {});
const store = new Vuex.Store({
  modules,
  getters,
});

export default store;
